﻿<UserControl x:Class="JayDev.MediaScribe.View.Controls.ImageButton"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:nmControls="clr-namespace:JayDev.MediaScribe.View.Controls"
             xmlns:MediaScribeCommon="clr-namespace:JayDev.MediaScribe.Common"
    xmlns:effect="clr-namespace:GrayscaleEffect;assembly=GrayscaleEffect"
             mc:Ignorable="d" 
             x:Name="ImageButtonName"
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Style x:Key="ChangeMyFonts" TargetType="{x:Type TextBlock}">
            <Setter Property="FontSize" Value="11" />
        </Style>


        <ControlTemplate x:Key="buttonTemplateWithNoWhiteBorder" TargetType="ButtonBase" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
            <nmControls:CustomButtonChrome Background="{TemplateBinding Panel.Background}" BorderBrush="{TemplateBinding Border.BorderBrush}" RenderDefaulted="{TemplateBinding Button.IsDefaulted}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" RenderPressed="{TemplateBinding ButtonBase.IsPressed}" x:Name="Chrome" SnapsToDevicePixels="True">
                <ContentPresenter RecognizesAccessKey="True" Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" Margin="{TemplateBinding Control.Padding}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
            </nmControls:CustomButtonChrome>
            <ControlTemplate.Triggers>
                <!--<Trigger Property="Chrome.IsEnabled">
                    <Setter Property="Chrome.BorderBrush">
                        <Setter.Value>
                            <SolidColorBrush>#F00</SolidColorBrush>
                        </Setter.Value>
                    </Setter>
                    <Trigger.Value>
                        <s:Boolean>False</s:Boolean>
                    </Trigger.Value>
                </Trigger>-->
                <Trigger Property="UIElement.IsKeyboardFocused">
                    <Setter Property="mwt:ButtonChrome.RenderDefaulted" TargetName="Chrome">
                        <Setter.Value>
                            <s:Boolean>True</s:Boolean>
                        </Setter.Value>
                    </Setter>
                    <Trigger.Value>
                        <s:Boolean>True</s:Boolean>
                    </Trigger.Value>
                </Trigger>
                <Trigger Property="ToggleButton.IsChecked">
                    <Setter Property="mwt:ButtonChrome.RenderPressed" TargetName="Chrome">
                        <Setter.Value>
                            <s:Boolean>True</s:Boolean>
                        </Setter.Value>
                    </Setter>
                    <Trigger.Value>
                        <s:Boolean>True</s:Boolean>
                    </Trigger.Value>
                </Trigger>
                <Trigger Property="UIElement.IsEnabled">
                    <Setter Property="TextElement.Foreground">
                        <Setter.Value>
                            <SolidColorBrush>#FFADADAD</SolidColorBrush>
                        </Setter.Value>
                    </Setter>
                    <Trigger.Value>
                        <s:Boolean>False</s:Boolean>
                    </Trigger.Value>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

    </UserControl.Resources>
    
    <Button x:Name="myButton" Template="{StaticResource buttonTemplateWithNoWhiteBorder}" Background="Transparent" BorderThickness="0" BorderBrush="Transparent">
        <Button.Style>
            <Style TargetType="{x:Type Button}">
                <Style.Triggers>
                    <Trigger Property="Control.IsEnabled" Value="false">
                        <Setter Property="Control.Opacity" Value="0.3" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
        <Image x:Name="myImage" Source="{Binding ElementName=ImageButtonName, Path=MySource, Mode=TwoWay}" >
            <Image.Effect>
                <effect:GrayscaleEffect DesaturationFactor="{Binding ElementName=myButton, Path=IsEnabled}"/>
            </Image.Effect>
        </Image>
    </Button>
</UserControl>